<?php

function login_user($user,$pass)
{
	include("tier1.php");  
	$query="select * from member where username='$user' and password='$pass'";
	$result=exec_sql_query($query);
	if($user!="" && $pass!="")
	{
		if(mysql_num_rows($result)==0)
		{   
			echo "<center><h4><font color='red'>Wrong Password or Username</p></h4></font>";
		}
		else
		{
			session_start();
			$_SESSION['user']=$user;
			header('Location: http://localhost:8080/gkogkopoulos-mpoididis/');
		}
	}
	else
		echo "<center><h4><font color='red'>Fill all fields!</p></h4></font>";
}	
	
//#############################################################################	
	
	
function insert_member($user,$pass,$email,$member_type)
{
	include("tier1.php");  
	$query = "select * from member where username='$user' ";
	$result= exec_sql_query($query);
	if (mysql_num_rows($result)>0)
	{
		echo "<center><h4><font color='red'>Username already exists</p></h4></font>";
	}
	else
	{
		if($user!="" && $pass!="" && $email!="")
		{
	  		$query="insert into member (username,password,email,type_id) values ('$user','$pass','$email','$member_type')";
	  		$result=exec_sql_query($query);
	  		echo "<center><h2><font color='red'>Welcome ".$user." to IGDB!!!</p></h2></font>" ;
		}
		else
		{
			echo "<center><h4><font color='red'>Fill all fields!</p></h4></font>";
		}
	}	
}

//#############################################################################


function delete_member($user)
{
	$query="delete from member where username='$user'";
	$result= exec_sql_query($query);
	echo "<center><h2><font color='red'>".$user." deleted from database</p></h2></font>" ;
}

//#############################################################################

function update_member($user,$pass,$email,$member_type)
{
		if($user!="" && $pass!="" && $email!="")
		{
	  		$query="update member set username='$user',password='$pass',email='$email',type_id='$member_type' where username='$user'";
	  		$result=exec_sql_query($query);
	  		echo "<center><h2><font color='red'>Changes saved!</p></h2></font>" ;
		}
		else
		{
			echo "<center><h4><font color='red'>Fill all fields!</p></h4></font>";
		}
}
?>
